package basic.com.liz.common.utils.jpa;

import javax.persistence.EntityManager;

import org.springframework.data.jpa.repository.query.CommonJpaQueryLookupStrategy;
import org.springframework.data.jpa.repository.query.QueryExtractor;
import org.springframework.data.jpa.repository.support.JpaRepositoryFactory;
import org.springframework.data.jpa.repository.support.PersistenceProvider;
import org.springframework.data.repository.query.QueryLookupStrategy;
import org.springframework.data.repository.query.QueryLookupStrategy.Key;

public class CommonJpaRepositoryFactory extends JpaRepositoryFactory
{
    private final EntityManager entityManager;
    private final QueryExtractor extractor;
    
    public CommonJpaRepositoryFactory(EntityManager entityManager)
    {
        super(entityManager);
        this.entityManager = entityManager;
        this.extractor = PersistenceProvider.fromEntityManager(entityManager);
        
    }

    @Override
    protected QueryLookupStrategy getQueryLookupStrategy(Key key)
    {
        return CommonJpaQueryLookupStrategy.create(entityManager, key, extractor);
    }
}
